import vueFeaturesRoutes from "../../router/models/vue-features-routes";
import router from "@/router/index";
export default {
	namespaced: true, // 命名空间
	state: {
		roles: ["admin", "edit"],
	},
	mutations: {
		LOG_OUT(state, val) {},
		EDIT_ROLE(state, val) {
			state.roles = val;
		},
	},
	actions: {
		logout({ commit }) {
			return new Promise((resolve, reject) => {
				commit("LOG_OUT");
				resolve();
			});
		},
		/* 登录后获取路由，再添加路由 */
		A_setMenuList({ commit }, payload) {
			// vueFeaturesRoutes应该从后台拿
			return new Promise((resolve, reject) => {
				resolve(vueFeaturesRoutes);
			}).then(res => {
				router.addRoute(...res);
			});
		},

		// 如果我们利用 async / await (opens new window)，我们可以如下组合 action：
		// async actionA ({ commit }) {
		//   commit('gotData', await getData())
		// },
		// async actionB ({ dispatch, commit }) {
		//   await dispatch('actionA') // 等待 actionA 完成
		//   commit('gotOtherData', await getOtherData())
		// },

		// 对于模块内部的 action，局部状态通过 context.state 暴露出来，根节点状态则为
		// incrementIfOddOnRootSum ({ state, commit, rootState }) {
		//   if ((state.count + rootState.count) % 2 === 1) {
		//     commit('increment')
		//   }
		// }
	},
	// 对于模块内部的 getter，根节点状态会作为第三个参数暴露出来：
	getters: {
		sumWithRootCount(state, getters, rootState) {
			return state.count + rootState.count;
		},
	},
};
